<?php
require "../load.php";
error_reporting(0);
$action = $_POST["action"];
unset($_POST["action"]);
if (get_magic_quotes_gpc()) {
    $_POST = Owl_Format::stripslashes_deep($_POST);
}

switch($action) {
    case "change_color_scheme" :
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            die();
        }
        if (Owl_Theme_Control::change_color_scheme($_POST["color_scheme"])) {
            echo "<div class=\"ajax-success\">" . __("Change color scheme successful!!!") . "</div>";
        }
        else {
            global $owl_option;
            echo "<div class=\"ajax-error\">" . __("Error while changing color scheme"). ": " ;
            $owl_option->print_error();
            echo "</div>";
        }
        break;
    case "customize_theme" :
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            die();
        }
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
        header("Cache-Control: no-cache, must-revalidate" );
        header("Pragma: no-cache" );
        header("Content-type: text/x-json");
        if (Owl_Theme_Control::customize_theme($_POST)) {
            $data = array(
                "code" => 1,
                "message" => "<div class=\"ajax-success\">" . __("Customize theme successful!!!") . "</div>"
            );
        }
        else {
            $data = array(
                "code" => 1,
                "message" => "<div class=\"ajax-error\">" . __("Error while customizing theme"). ":<br /> " .
                             sprintf(__("May be the <code>%s</code> file is not writable at the moment"), THEME_CUSTOMIZE) .
                             "</div>"
            );
        }
        $send = Owl_Functions::json_encode($data);
        echo $send;
        break;
    case "set_default_customization" :
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            die();
        }
        
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
        header("Cache-Control: no-cache, must-revalidate" );
        header("Pragma: no-cache" );
        header("Content-type: text/x-json");
        if (Owl_Theme_Control::set_default_customization()) {
            $data = array(
                "code" => 1,
                "message" => __("Revert to default successful!!!")
            );
        }
        else {
            $data = array(
                "code" => 0,
                "message" => "<div class=\"ajax-error\">" . __("Error while reverting to default"). ":<br /> " .
                             sprintf(__("May be the <code>%s</code> file is not writable at the moment"), THEME_CUSTOMIZE) .
                             "</div>"
            );
        }
        $send = Owl_Functions::json_encode($data);
        echo $send;
        break;
    case "change_theme" :
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            die();
        }
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
        header("Cache-Control: no-cache, must-revalidate" );
        header("Pragma: no-cache" );
        header("Content-type: text/x-json");
        if (Owl_Theme_Control::change_theme($_POST["theme"])) {
            $data = array(
                "code" => 1,
                "message" => __("Change theme successful!!!")
            );
        }
        else {
            $data = array(
                "code" => 0,
                "message" => "<div class=\"ajax-error\">" . __("Error while changing theme"). ":<br /> " .
                             sprintf(__("May be the <code>%s</code> file is not writable at the moment"), "option.xml") .
                             "</div>"
            );
        }
        $send = Owl_Functions::json_encode($data);
        echo $send;
        break;
    default:
    die();

}

die();
